home *** CD-ROM | disk | FTP | other *** search
/ Online Today 2000 January / Onto0100.iso / pc / Browser / HTML Kurse / selfhtml / zticker.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-10-14  |  6.8 KB  |  272 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Dimension;
  5. import java.awt.Event;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.net.URL;
  11. import java.util.Date;
  12. import java.util.StringTokenizer;
  13.  
  14. public class zticker extends Applet implements Runnable {
  15.    // $FF: renamed from: im java.awt.Image
  16.    public Image field_0;
  17.    // $FF: renamed from: gr java.awt.Graphics
  18.    public Graphics field_1;
  19.    public String message;
  20.    public Font messageF;
  21.    public int messageX;
  22.    public int messageY;
  23.    public int messageW;
  24.    public URL url_;
  25.    int speed;
  26.    // $FF: renamed from: t java.lang.Thread
  27.    public Thread field_2;
  28.    public Color txtCo;
  29.    public int txtStyle;
  30.    public Color shCo1;
  31.    public Color shCo2;
  32.    public Color hrefCo;
  33.    public Color bgCo;
  34.    public boolean ExFill;
  35.    public boolean expired = false;
  36.    public boolean useShadow;
  37.    public boolean useFrame;
  38.    public Dimension lastS = new Dimension(1, 1);
  39.  
  40.    public String fixedgetParameter(String var1) {
  41.       char[] var2 = var1.toCharArray();
  42.  
  43.       for(int var3 = 0; var3 < var2.length; ++var3) {
  44.          var2[var3] = (char)(var2[var3] & 255);
  45.       }
  46.  
  47.       return new String(var2);
  48.    }
  49.  
  50.    public void init() {
  51.       Date var1 = new Date();
  52.       String var3 = ((Applet)this).getParameter("msg");
  53.       this.message = var3 == null ? "zticker for beta" : this.fixedgetParameter(var3);
  54.       this.bgCo = this.readColor(((Applet)this).getParameter("exp"), Color.white);
  55.       if (!this.bgCo.equals(Color.white)) {
  56.          Date var2 = new Date(this.bgCo.getRed(), this.bgCo.getGreen() - 1, this.bgCo.getBlue());
  57.          this.expired = var1.after(var2);
  58.       }
  59.  
  60.       if (!this.expired) {
  61.          this.bgCo = this.readColor(((Applet)this).getParameter("start"), Color.black);
  62.          if (!this.bgCo.equals(Color.black)) {
  63.             Date var8 = new Date(this.bgCo.getRed(), this.bgCo.getGreen() - 1, this.bgCo.getBlue());
  64.             this.expired = var8.after(var1);
  65.          }
  66.       }
  67.  
  68.       this.ExFill = ((Applet)this).getParameter("exfill") != null;
  69.       if (this.expired && !this.ExFill) {
  70.          ((Applet)this).resize(2, 2);
  71.       } else {
  72.          this.speed = (var3 = ((Applet)this).getParameter("speed")) == null ? 10 : Integer.valueOf(var3);
  73.          if ((var3 = ((Applet)this).getParameter("href")) != null) {
  74.             try {
  75.                this.url_ = new URL(((Applet)this).getDocumentBase(), var3);
  76.             } catch (Exception var7) {
  77.                this.url_ = null;
  78.             }
  79.          }
  80.  
  81.          if (this.url_ == null) {
  82.             this.bgCo = Color.black;
  83.          } else {
  84.             this.bgCo = Color.blue;
  85.          }
  86.  
  87.          this.txtCo = this.readColor(((Applet)this).getParameter("txtco"), this.bgCo);
  88.          this.bgCo = this.readColor(((Applet)this).getParameter("bgco"), ((Component)this).getBackground());
  89.          this.shCo2 = this.readColor(((Applet)this).getParameter("shco"), this.bgCo);
  90.          this.useShadow = !this.shCo2.equals(this.bgCo);
  91.          this.hrefCo = this.readColor(((Applet)this).getParameter("hrefco"), Color.blue);
  92.          this.useFrame = !this.hrefCo.equals(this.bgCo);
  93.          this.txtStyle = this.useShadow ? 0 : 1;
  94.          if (this.useShadow) {
  95.             int var4 = this.shCo2.getRed() + this.txtCo.getRed() >> 1;
  96.             int var5 = this.shCo2.getGreen() + this.txtCo.getGreen() >> 1;
  97.             int var6 = this.shCo2.getBlue() + this.txtCo.getBlue() >> 1;
  98.             this.shCo1 = new Color(var4, var5, var6);
  99.          }
  100.  
  101.       }
  102.    }
  103.  
  104.    public String[][] getParameterInfo() {
  105.       String[][] var1 = new String[][]{{"msg", "String", "Message to display"}, {"href", "String", "url to switch to"}, {"speed", "int", "animation speed in pixels (10)"}, {"txtco", "int[3]", "RGB-Color of Message (black/blue)"}, {"hrefco", "int[3]", "RGB-Color of Frame (blue)"}, {"bgco", "int[3]", "RGB-Color of background (getBackground)"}, {"shco", "int[3]", "RGB-Color of Message (black/blue)"}, {"start", "int[3]", "Date to start: Y, M, D; if not set, show"}, {"exp", "int[3]", "Date to expire: Y, M, D; if not set, no expiration"}, {"exfill", "", "If exist, fill with bgco, if expired"}};
  106.       return var1;
  107.    }
  108.  
  109.    public String getAppletInfo() {
  110.       return "zticker.java, V b1.30, 02/07/96 by Thomas Wendt, http://www.uni-kassel.de/fb16/ipm/mt/staff/thwendte.html";
  111.    }
  112.  
  113.    public Color readColor(String var1, Color var2) {
  114.       if (var1 == null) {
  115.          return var2;
  116.       } else {
  117.          StringTokenizer var6 = new StringTokenizer(var1, ",");
  118.  
  119.          try {
  120.             int var3 = Integer.valueOf(var6.nextToken());
  121.             int var4 = Integer.valueOf(var6.nextToken());
  122.             int var5 = Integer.valueOf(var6.nextToken());
  123.             return new Color(var3, var4, var5);
  124.          } catch (Exception var7) {
  125.             return var2;
  126.          }
  127.       }
  128.    }
  129.  
  130.    public void createParams() {
  131.       int var1 = ((Component)this).size().width;
  132.       int var2 = ((Component)this).size().height;
  133.       this.lastS.width = var1;
  134.       this.lastS.height = var2;
  135.       byte var3 = 14;
  136.       Font var4 = new Font("TimesRoman", this.txtStyle, var3);
  137.       ((Component)this).setFont(var4);
  138.       FontMetrics var5 = ((Component)this).getFontMetrics(var4);
  139.       int var6 = var5.getHeight();
  140.       var6 = var3 * (var2 - 10) / var6;
  141.       this.messageF = new Font("TimesRoman", this.txtStyle, var6);
  142.       FontMetrics var7 = ((Component)this).getFontMetrics(this.messageF);
  143.       var6 = var7.getHeight();
  144.       this.messageX = var1;
  145.       this.messageY = (var2 - var6 >> 1) + var7.getAscent();
  146.       this.messageW = var7.stringWidth(this.message);
  147.       if (this.field_1 != null) {
  148.          this.field_1.dispose();
  149.       }
  150.  
  151.       this.field_0 = ((Component)this).createImage(this.lastS.width, this.lastS.height);
  152.       this.field_1 = this.field_0.getGraphics();
  153.    }
  154.  
  155.    public void paint(Graphics var1) {
  156.       this.update(var1);
  157.    }
  158.  
  159.    public synchronized void update(Graphics var1) {
  160.       int var2 = ((Component)this).size().width;
  161.       int var3 = ((Component)this).size().height;
  162.       if (this.expired) {
  163.          if (this.ExFill) {
  164.             var1.setColor(this.bgCo);
  165.             var1.fillRect(0, 0, var2, var3);
  166.          }
  167.  
  168.       } else {
  169.          if (var3 != this.lastS.height || var2 != this.lastS.width) {
  170.             this.createParams();
  171.          }
  172.  
  173.          this.field_1.setColor(this.bgCo);
  174.          this.field_1.fillRect(0, 0, var2, var3);
  175.          if (this.url_ != null && this.useFrame) {
  176.             this.field_1.setColor(this.hrefCo);
  177.             this.field_1.clipRect(0, 0, var2, var3);
  178.             this.field_1.drawRect(0, 0, var2, var3);
  179.             this.field_1.drawRect(1, 1, var2 - 2, var3 - 2);
  180.             this.field_1.setColor(this.bgCo);
  181.             this.field_1.draw3DRect(2, 2, var2 - 4, var3 - 4, true);
  182.             this.field_1.draw3DRect(3, 3, var2 - 6, var3 - 6, true);
  183.             this.field_1.clipRect(4, 4, var2 - 8, var3 - 8);
  184.          }
  185.  
  186.          this.field_1.setFont(this.messageF);
  187.          if (this.useShadow) {
  188.             this.field_1.setColor(this.shCo2);
  189.             this.field_1.drawString(this.message, this.messageX + 2, this.messageY + 1);
  190.             this.field_1.setColor(this.shCo1);
  191.             this.field_1.drawString(this.message, this.messageX + 1, this.messageY);
  192.          }
  193.  
  194.          this.field_1.setColor(this.txtCo);
  195.          this.field_1.drawString(this.message, this.messageX, this.messageY);
  196.          var1.drawImage(this.field_0, 0, 0, this);
  197.       }
  198.    }
  199.  
  200.    public void calcPos() {
  201.       this.messageX -= this.speed;
  202.       if (this.messageX + this.messageW < 0) {
  203.          this.messageX = ((Component)this).size().width;
  204.       }
  205.  
  206.    }
  207.  
  208.    public void run() {
  209.       if (!this.expired) {
  210.          Thread.currentThread().setPriority(1);
  211.  
  212.          while(this.field_2 != null) {
  213.             ((Component)this).repaint();
  214.             this.calcPos();
  215.  
  216.             try {
  217.                Thread.sleep(100L);
  218.             } catch (InterruptedException var1) {
  219.             }
  220.          }
  221.  
  222.       }
  223.    }
  224.  
  225.    public void start() {
  226.       if (this.field_2 == null) {
  227.          this.field_2 = new Thread(this);
  228.          this.field_2.start();
  229.       }
  230.  
  231.    }
  232.  
  233.    public void stop() {
  234.       if (this.field_2 != null) {
  235.          this.field_2.stop();
  236.          this.field_2 = null;
  237.       }
  238.  
  239.       this.field_0 = null;
  240.       if (this.field_1 != null) {
  241.          this.field_1.dispose();
  242.          this.field_1 = null;
  243.       }
  244.  
  245.       this.lastS = new Dimension(1, 1);
  246.    }
  247.  
  248.    public boolean mouseUp(Event var1, int var2, int var3) {
  249.       if (this.url_ != null) {
  250.          ((Applet)this).getAppletContext().showDocument(this.url_);
  251.       }
  252.  
  253.       return true;
  254.    }
  255.  
  256.    public boolean mouseEnter(Event var1, int var2, int var3) {
  257.       if (this.url_ != null) {
  258.          ((Applet)this).showStatus(this.url_.toExternalForm());
  259.       }
  260.  
  261.       return true;
  262.    }
  263.  
  264.    public boolean mouseExit(Event var1, int var2, int var3) {
  265.       if (this.url_ != null) {
  266.          ((Applet)this).showStatus("  ");
  267.       }
  268.  
  269.       return true;
  270.    }
  271. }
  272.